<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *员工管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'vip';
$tabs=array(
	array('op'=>'vip','title'=>'VIP会员列表'),
	array('op'=>'list','title'=>'普通会员列表'),
	array('op'=>'black','title'=>'黑名单'),	
);
if($_RQ['op']=='vip'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	$params['isblack']=0;
	$params['isvip']=1;
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_erp_vip',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as $k=>&$item){
			$memebr = pdo_get('core_members',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['mid']),array('nickname','avatar'));
			$item['nickname']=$memebr['nickname'];
			$item['avatar']=$memebr['avatar'];
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'list'=>array(
			array('name'=>'mid','title'=>'会员ID','type'=>'string'),
			array('name'=>'nickname','title'=>'昵称','type'=>'string'),
			array('name'=>'avatar','title'=>'头像','type'=>'image'),
			array('name'=>'isblack','title'=>'是否拉黑','type'=>'switch','set'=>'set'),
		)),
		'search'=>array(
			array('name'=>'mid','width'=>15,'title'=>'会员ID','type'=>'string'),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='list'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	$params['isblack']=0;
	$params['isvip']=0;
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_erp_vip',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as $k=>&$item){
			$memebr = pdo_get('core_members',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['mid']),array('nickname','avatar'));
			$item['nickname']=$memebr['nickname'];
			$item['avatar']=$memebr['avatar'];
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'list'=>array(
			array('name'=>'mid','title'=>'会员ID','type'=>'string'),
			array('name'=>'nickname','title'=>'昵称','type'=>'string'),
			array('name'=>'avatar','title'=>'头像','type'=>'image'),
			array('name'=>'isblack','title'=>'是否拉黑','type'=>'switch','set'=>'set'),
		)),
		'search'=>array(
			array('name'=>'mid','width'=>15,'title'=>'会员ID','type'=>'string'),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='black'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	$params['isblack']=1;
	$params['isvip']=1;
	if(!empty($_RQ['nickname'])){
		$params['nickname like']='%'.trim($_RQ['nickname']).'%';
		$return['params']['nickname']=$_RQ['nickname'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_erp_vip',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$memebr = pdo_get('core_members',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['mid']),array('nickname','avatar'));
			$item['nickname']=$memebr['nickname'];
			$item['avatar']=$memebr['avatar'];
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'list'=>array(
			array('name'=>'nickname','title'=>'昵称','type'=>'string'),
			array('name'=>'avatar','title'=>'头像','type'=>'image'),
			array('name'=>'isblack','title'=>'是否拉黑','type'=>'switch','set'=>'set'),
		)),
		'search'=>array(
			array('name'=>'nickname','width'=>15,'title'=>'昵称','type'=>'string'),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}

if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_erp_vip',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}
if($_RQ['op']=='set'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择要编辑的用户！','error');
	}
	$post=get_postdata();
	if(isset($post['isblack'])){
		pdo_update('jy_erp_vip',array('isblack'=>intval($post['isblack'])),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	exi('操作成功！');
}